import ddt
import os
import unittest
from autoframe.page.register_page import RegisterEcshop
from autoframe.common.functions import open_browser
from autoframe.common.data_operation import DataOperation
from autoframe.page.index_page import *
from autoframe.common.base import Base
import time

project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
path = os.path.join(project_path, "data/user.xls")
user_list = DataOperation(path).get_data_to_dict()


@ddt.ddt()
class RegisterTestCase(unittest.TestCase,Base):

    @classmethod
    def setUpClass(cls) -> None:
        cls.register = RegisterEcshop(open_browser())

    @ddt.data(*user_list)
    def test_register(self, data):
        # 请求网址
        self.register.get("http://172.16.140.57/ecshop/user.php?act=register")
        # 定位到用户名输入框
        self.register.ipt_username(data["username"])
        # 定位到邮箱输入框
        self.register.ipt_email(data["email"])
        # 定位到密码输入框
        self.register.ipt_password(data["password"])
        # 定位到确认密码输入框
        self.register.ipt_confirm_password(data["conform_password"])
        # 定位到手机输入框
        self.register.ipt_phone_number(data["mobile_phone"])
        # 定位到注册按钮并点击
        self.register.click_register()
        # 定位成功注册之后的文本显示
        username = self.register.text1()
        # 断言比较
        self.assertEqual(data["username"], username)

    def tearDown(self) -> None:
        time.sleep(2)
        self.register.a_logout(2)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.register.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)